class Solution
{
public:
    vector<vector<int>> flipAndInvertImage(vector<vector<int>> &image)
    {
        int n = image.size();
        int halfN = n / 2;
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < halfN; ++j)
            {
                swap(image[i][j], image[i][n - 1 - j]);
            }
        }
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                image[i][j] = !image[i][j];
            }
        }
        return image;
    }
};